package com.kexun.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kexun.common.PageResult;
import com.kexun.common.utils.ResponseEntity;
import com.kexun.entity.DO.Shop;
import com.kexun.service.ShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("system/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @GetMapping("list")
    public String list() {
        return "shop/shop_list";
    }

    @ResponseBody
    @PostMapping("list")
    public PageResult list(String shopName, int page, int limit) {
        IPage<Shop> shopList = shopService.findShopList(shopName, page, limit);
        return new PageResult(shopList.getRecords(), shopList.getTotal());
    }

    @ResponseBody
    @PostMapping("upd_show_state")
    public ResponseEntity updShowState(boolean state, int id) {
        shopService.updShowState(state, id);
        return new ResponseEntity().success();
    }

    @GetMapping("add")
    public String add() {
        return "shop/shop_add";
    }

    @ResponseBody
    @PostMapping("add")
    public ResponseEntity add(Shop shop) {
        shopService.addShop(shop);
        return new ResponseEntity().success();
    }


    @ResponseBody
    @PostMapping("del")
    public ResponseEntity del(int id) {
        shopService.deleteById(id);
        return new ResponseEntity().success();
    }

}
